package a10_动态规划;

/**
 * <p>
 * a17_一和零复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/24
 */
public class a17_一和零复习2 {

    public static void main(String[] args) {
        a17_一和零复习2 test = new a17_一和零复习2();
        test.findMaxForm(new String[]{"10","0001","111001","1","0"}, 5, 3);
    }

    //dp[i][j]:代表i个0和j个1最大子集长度
    public int findMaxForm(String[] strs, int m, int n) {
        int[][] dp = new int[m+1][n+1];
        dp[0][0] = 0;

        //遍历物品
        for (String str : strs) {
            int x = 0;
            int y = 0;
            for (char c : str.toCharArray()) {
                if(c == '0'){
                    x++;
                }else {
                    y++;
                }
            }
            for (int i = m; i >= 0; i--) {
                for (int j = n; j >= 0; j--) {
                    if(i >= x && j >= y){
                        dp[i][j] = Math.max(dp[i][j],dp[i-x][j-y] + 1);
                    }

                }
            }
        }

        return dp[m][n];
    }
}
